// pages/mainOperation/orderDetails/orderdetails.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //业务类型
    BizTypeID: '',
    //办理城市
    CityID: '',
    //姓名
    UserName: '',
    //身份证号
    IDNum: '',
    //手机号
    UserMobile: '',
    //变更前手机
    BeforeMobile: '',
    //变更后手机
    AfterMobile: '',
    //车牌号
    PlateNo: '',
    //车辆标识代码
    VIN: '',
    //是否省内
    IsProvince: '',
    //准驾车型
    LicenceClass: '',
    //降级后准驾车型
    LowLicenceClass: '',
    //驾驶证正本照片
    DrivingLicence: '',
    //驾驶证副本照片
    DrivingLicenceBack: '',
    //交强险副本原件照片
    Compulsory: '',
    //原机动车号牌
    BeforePlateNo: '',
    //原机动车号牌照片
    AfterPlateNo: '',
    //临时牌照原件正面
    TemporaryLicence: '',
    //临时牌照反面
    TemporaryLicenceBack: '',
    //说明描述
    OrderDesc: '',
    //申请人
    UserID: '',
    //订单金额
    OrderPrice: '',
    //工本费
    CostPrice: '',
    //邮寄费用
    ExpressFee: '',
    //收件地址
    MailAddressID: '',
    // 快递公司
    ExpressCompanyID: '',
    // 行驶证正面照片
    VehicleLicence: '',
    // 行驶证背面照片
    VehicleLicenceBack: '',
    // 体检医院
    HospitalID: '',
    //体检医院
    HospitalName: '',
    //业务类型
    BizTypeName: '',
    //订单状态
    OrderStateTxt: '',
    MailAreaAddress: '',
    MailAddress: '',
    MailUserMobile: '',
    MailUserName: '',
    MailNumber:'2312312313123123',     //新增快递单号，暂时先写死
    auditList: [],
    OrderId: 0, //订单id
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData(options);
    this.getOrderDetail();
    this.getAudit();
  },
  /**
   * 获取订单详情
   */
  getOrderDetail() {
    let self = this;
    let url = app.apiBaseUrl + "/RegOrder/GetOrderDetail";

    app.httpRequest({
      method: "GET",
      url: url,
      showLoading: true,
      data: {
        orderId: self.data.OrderId
      },
      success: function(res) {
        let rdata = res.data;
        if (rdata.status == 0) {
          self.setData(rdata.data);
          self.setData({
            MailAddress: rdata.data.MailModel.MailAddress,
            MailUserMobile: rdata.data.MailModel.MailUserMobile,
            MailUserName: rdata.data.MailModel.MailUserName,
            MailAreaAddress: rdata.data.MailModel.MailAreaAddress
          });
        } else {
          wx.showToast({
            title: rdata.message
          });
        }
      }
    });
  },
  /**
   * 获取审核记录
   */
  getAudit() {
    let self = this;
    let url = app.apiBaseUrl + "/RegOrder/GetAudit";

    app.httpRequest({
      method: "GET",
      url: url,
      showLoading: true,
      data: {
        orderId: self.data.OrderId
      },
      success: function(res) {
        let rdata = res.data;
        if (rdata.status == 0) {
          self.setData({
            auditList: rdata.data
          });

        } else {
          wx.showToast({
            title: rdata.message
          });
        }
      }
    });
  },
  /**
 * 图片上传成功以后的预览
 */
  previewImageTap: function (e) {
    let self = this;
    console.log('图片预览');
    let src = e.currentTarget.dataset.imgsrc;
    console.log('src',src);
    let previewImageCurrent;    //当前被预览的图片路径
    switch (src) {
      case 'DrivingLicence':     //驾驶证正本
        previewImageCurrent = self.data.DrivingLicence;
        break;
      case 'DrivingLicenceBack':     //驾驶证背面
        previewImageCurrent = self.data.DrivingLicenceBack;
        break;
      case 'Compulsory':     //交强险副本
        previewImageCurrent = self.data.DrivingLicenceBack;
        break;
      case 'BeforePlateNo':     //原机动车号牌
        previewImageCurrent = self.data.BeforePlateNo;
        break;
      case 'AfterPlateNo':     //变更后机动车号牌
        previewImageCurrent = self.data.AfterPlateNo;
        break;
      case 'TemporaryLicence':     //临时牌照原件正面
        previewImageCurrent = self.data.TemporaryLicence;
        break;
      case 'TemporaryLicenceBack':     //临时牌照原件反面
        previewImageCurrent = self.data.TemporaryLicenceBack;
        break;
      case 'VehicleLicence':     //行驶证正面照片
        previewImageCurrent = self.data.VehicleLicence;
        break;
      case 'VehicleLicenceBack':     //行驶证背面照片
        previewImageCurrent = self.data.VehicleLicenceBack;
        break;
    }
    let previewImageUrls = [];  //所要预览的所有图片路径数组
    //多张图片只要有一张上传成功，就可以进行图片预览
    if (self.data.DrivingLicence) {
      previewImageUrls.push(self.data.DrivingLicence);
    } 
    if (self.data.DrivingLicenceBack){
      previewImageUrls.push(self.data.DrivingLicenceBack);
    }
    if (self.data.Compulsory){
      previewImageUrls.push(self.data.Compulsory);
    }
    if (self.data.BeforePlateNo){
      previewImageUrls.push(self.data.BeforePlateNo);
    }
    if (self.data.AfterPlateNo){
      previewImageUrls.push(self.data.AfterPlateNo);
    }
    if (self.data.TemporaryLicence){
      previewImageUrls.push(self.data.TemporaryLicence);
    }
    if (self.data.TemporaryLicenceBack){
      previewImageUrls.push(self.data.TemporaryLicenceBack);
    } 
    if (self.data.VehicleLicence){
      previewImageUrls.push(self.data.VehicleLicence);
    }
    if (self.data.VehicleLicenceBack){
      previewImageUrls.push(self.data.VehicleLicenceBack);
    }
    wx.previewImage({
      current: previewImageCurrent, // 当前显示图片的http链接
      urls: previewImageUrls // 需要预览的图片http链接列表
    })
    console.log('previewImageCurrent', previewImageCurrent);
    console.log('previewImageUrls', previewImageUrls);
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})